<?php

namespace Biz\service\springHomeDecActivity;

use Biz\cache\brand\Brand as cBrand;
use Biz\pockets\constInterface\SpringHomeDecConfig;
use Doraemon\pockets\action\ApiAction;
use Doraemon\tools\Hhzurl;

class Util implements SpringHomeDecConfig
{
    /**
     * 判断是否为测试环境
     * @return int
     */
    public static function isTest()
    {
        return self::IS_TEST ? 1 : 0;
    }

    /**
     * 检查app版本是否可用
     * @param $currentVersion
     * @return bool
     */
    public static function versionCheck($currentVersion)
    {
        if (version_compare($currentVersion, self::MIN_APP_VERSION, ">=")) {
            return true;
        }
        return false;
    }

    /**
     * 限制提交频率
     * @param $key
     * @return bool
     */
    public static function lockSubmit($lockKey)
    {
        if (cBrand::isLock($lockKey, 3)) {
            throw new \Exception("请勿重复提交！", ApiAction::CODE_ERROR_VIEW_TOSTA);
        }
    }

    /**
     * 个人主页地址
     */
    public static function myFloatUrl($uid, $self = true): string
    {
        $url = $self ? '/brand/home-decoration-festival/main-hall?wish_uid=' . $uid : '/brand/home-decoration-festival/set-up-result?uid=' . $uid;
        return Hhzurl::getDomain() . $url;
    }

    /**
     * 获取活动内容展示时间
     * @return string
     */
    public static function getContentShowDate()
    {
        $date = date('Y-m-d', time());
        $activityBeginTime = strtotime(self::ACTIVITY_TIME_START);
        if (time() < $activityBeginTime) {
            $date = date('Y-m-d', $activityBeginTime);
        }
        $activityEndTime = strtotime(self::ACTIVITY_TIME_END);
        if (time() >= $activityEndTime) {
            $date = date('Y-m-d', $activityEndTime);
        }
        return $date;
    }

}